package com.legendframework.core.cmd.paramer.converter.impl;

import com.legendframework.core.ioc.IParameter;
import com.legendframework.core.ioc.annotation.Component;
import com.legendframework.core.cmd.exception.ParameterCastException;
import org.bukkit.command.CommandSender;

@Component
public class ByteParamerConverter extends AbstractNumberTypeParamerConverter<Byte> {

    @Override
    public boolean check(Class<?> cls) {
        return byte.class == cls || Byte.class == cls;
    }

    @Override
    protected Byte castValue(CommandSender sender, String message, Class<Byte> type, IParameter parameter) {
        try {
            return Byte.parseByte(message);
        } catch (NumberFormatException e) {
            throw new ParameterCastException("参数: "+message +" , 无法转换为类型: "+ type.getName());
        }
    }
}
